/**
* @file drv_lcd.c
* @brief  lcd interface
* @details 
* @author huangbin
* @version V1.0.0
* @date 2025-04-20
* @copyright All documents are copyrighted by Shenzhen Xinlongwei Technology Co., LTD.
*            They may not be used for commercial purposes without permission
*/
#include "inc.h"
#include "drv_lcd.h"


static DRVLCD drvLcd[SCREEN_MAX];

//注册显示设备
bool lcdRegisterDevice(SCREEN_Type screen,lcdDeviceInit init)
{
    if(screen < SCREEN_MAX)
    {
        memset(&drvLcd[screen],0,sizeof(DRVLCD));
        init(&drvLcd[screen]);
        return true;
    }
    DebugPrintf("[LCD] lcd register device fail\r\n");
    return false;
}
//获取lcd操作指针
DRVLCD *lcdGetDevicePointer(SCREEN_Type screen)
{
     if(screen < SCREEN_MAX)
        return &drvLcd[screen];
     DebugPrintf("[LCD] lcd device get fail\r\n");
     return false;
}
void lcdBackLightSet(SCREEN_Type screen,uint8_t duty)
{
    DRVLCD *pLcd;
    
    pLcd = lcdGetDevicePointer(screen);
    if(pLcd && pLcd->BkSet)
    {
        pLcd->BkSet(duty);
    }
}
//提供一个arm2d的16bit移植接口
static DRVLCD *pLcd = &drvLcd[SCREEN_SUB1];
void Disp0_DrawBitmap (uint32_t x,uint32_t y,uint32_t width,uint32_t height,const uint8_t *bitmap)
{
	pLcd->SetWindow(x,y,x+width,y+height);
	pLcd->WriteData((uint16_t *)bitmap,width * height);
}
//LCD测试图
void lcdTestPattern(void)
{
    DRVLCD *pLcd;
    pLcd = lcdGetDevicePointer(SCREEN_SUB1);
    pLcd->SetWindow(0,0,pLcd->x,pLcd->y);
    pLcd->WriteColor(MAKE_COLOR(255,0,0),pLcd->x*(pLcd->y/8));
    pLcd->WriteColor(MAKE_COLOR(0,255,0),pLcd->x*(pLcd->y/8));
    pLcd->WriteColor(MAKE_COLOR(0,0,255),pLcd->x*(pLcd->y/8));
    pLcd->WriteColor(MAKE_COLOR(255,0,255),pLcd->x*(pLcd->y/8));
    pLcd->WriteColor(MAKE_COLOR(255,255,0),pLcd->x*(pLcd->y/8));
    pLcd->WriteColor(MAKE_COLOR(0,255,255),pLcd->x*(pLcd->y/8));
    pLcd->WriteColor(MAKE_COLOR(0,0,0),pLcd->x*(pLcd->y/8));
    pLcd->WriteColor(MAKE_COLOR(255,255,255),pLcd->x*(pLcd->y/8));
    lcdBackLightSet(SCREEN_SUB1,LCD_BACKLIGHT_ON);
}

/************************END OF FILE*********************************************/

